<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <th:block th:include="fragments/header :: header"/>
    <script type="text/javascript" th:inline="none">
        $(function () {
            initDataGrid();
            initToolbar();
        });

        function initDataGrid() {
            $("#dgResourcesList").datagrid({
                url:'/markt/resources/list',
                idField:'id',
                frozenColumns:[[
                    {field:'ck',checkbox:true}
                ]],
                columns:[[
                    {field: 'name', title: '名称', width: 100},
                    {field: 'url',title: '地址',width: 120},
                    {field: 'descript',title: '描述',width: 120}
                ]],
                pagination:true,
                rownumbers:true,
                fit:true,
                toolbar:'#dgResourcesList-toolbar'
            })
        }

        function initToolbar() {
            $("#btnAdd").click(function () {
                layer.open({
                    type:2,
                    area:['500px','300px'],
                    content:'/markt/resources/add',
                    end: function () {
                        $("#dgResourcesList").datagrid("reload");
                    }
                });
            });

            $("#btnEdit").click(function () {
                var sel = $("#dgResourcesList").datagrid('getSelected');
                if (sel) {
                    layer.open({
                        type: 2,
                        area:['500px','300px'],
                        content: '/markt/resources/edit/' + sel.id,
                        end: function () {
                            $("#dgResourcesList").datagrid("reload");
                        }
                    });
                }else {
                    layer.msg("请选择要修改的项！");
                }
            });

            $("#btnRemove").click(function () {
                DataGridUtil.Delete("/markt/resources/doDelete","dgResourcesList");
            });
        }
    </script>
</head>
<body class="easyui-layout">
<div id="dgResourcesList-toolbar" style="padding: 2px 0;" class="datagrid-toolbar">
    <table cellpadding="0" cellspacing="0" style="width: 100%">
        <tr>
            <td style="padding-left: 2px">
                <a id="btnAdd" href="javascript:void(0)" class="easyui-linkbutton" style="float: left">新增</a>
                <a id="btnEdit" href="javascript:void(0)" class="easyui-linkbutton" style="float: left">编辑</a>
                <a id="btnRemove" href="javascript:void(0)" class="easyui-linkbutton" style="float: left">删除</a>
            </td>
        </tr>
    </table>
</div>
<div data-options="region:'center'">
    <table id="dgResourcesList">
    </table>
</div>
</body>
</html>
